package com.mega.ycy.mixin;

import com.mega.ycy.common.item.ItemAYiSlashBlade;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.resources.I18n;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@SuppressWarnings({"MixinAnnotationTarget", "UnresolvedMixinReference"})
@Mixin(GuiButton.class)
public abstract class ButtonsMixin extends Gui {
    @Shadow public String displayString;

    /**
     * @author mouseReleased
     */
    @Inject(method = "func_146118_a", at = @At("HEAD"))
    public void released(int mouseX, int mouseY, CallbackInfo ci) {
        if (displayString.equals(I18n.format("deathScreen.respawn"))) {
            if (Minecraft.getMinecraft().player != null) {
                ItemAYiSlashBlade.ycy_death2.remove(Minecraft.getMinecraft().player);
                ItemAYiSlashBlade.ycy_death.remove(Minecraft.getMinecraft().player.entityUniqueID);
                Minecraft.getMinecraft().player.respawnPlayer();
            }
        }
    }
}
